
package org.sopt.dev.ImgKnight.agent.RobotsExclusion;

import org.apache.commons.collections.map.LRUMap;

public class LRUCacheEngine extends RobotsTxtCacheEngine<String, String[]> {

	private LRUMap lruMap = null;
	
	public LRUCacheEngine(int limitSize) {
		super(limitSize);
		lruMap = new LRUMap(limitSize);
	}
	
	public synchronized String[] put(String key, String[] value) {
		return (String [])lruMap.put(key, value);
	}
	
	public synchronized String[] get(String key) {
		super.totalAcces++;
		String[] rules = (String [])lruMap.get(key);
		if( rules != null ) {
			hitRate++;
			return rules;
		}
		else
			missrate++;
		return null;
	}
	
	public synchronized void clear() {
		lruMap.clear();
	}
	
	public synchronized int size() {
		return lruMap.size();
	}
	
}
